{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import dependencies and modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Libraries\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import h5py\n",
    "import xarray as xr\n",
    "import glob as glob\n",
    "import sys\n",
    "\n",
    "# Our modules\n",
    "sys.path.append('/home/jovyan/segtrax/source')\n",
    "import utils as ut\n",
    "import reader as rd\n",
    "from trajectory import Trajectory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Test functionality on one file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ATL10 file: data/ATL10_tracks/161185873/processed_ATL10-01_20181106165654_05970101_001_01.h5\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([10731962.93103843, 10731962.93103843, 10731962.93103843, ...,\n",
       "       11127873.41958201, 11127880.83395744, 11127888.1877479 ])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file = 'data/ATL10_tracks/161185873/processed_ATL10-01_20181106165654_05970101_001_01.h5'\n",
    "segment_id, segment_length, date, lons, lats, freeboard = rd.getATL10(file, beam='gt1l')\n",
    "\n",
    "segment_length"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Initialize list of objects\n",
    "1. Get list of data files with glob library\n",
    "2. Iterate through each file and create a trajectory object with that file's data. Add the object to a list.\n",
    "\n",
    "Potential improvements: simplify .h5 files and use parallelization stuff from Fernando's tutorial?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161109914/processed_ATL10-01_20181105062227_05750101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161053169/processed_ATL10-01_20181102153049_05350101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161184155/processed_ATL10-01_20181101190501_05220101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161184173/processed_ATL10-01_20181102201341_05380101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161185873/processed_ATL10-01_20181106165654_05970101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161156884/processed_ATL10-01_20181103040509_05430101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161182786/processed_ATL10-01_20181101155626_05200101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161187844/processed_ATL10-01_20181101142209_05190101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161156880/processed_ATL10-01_20181103212220_05540101_001_01.h5\n",
      "ATL10 file: /home/jovyan/segtrax/data/ATL10_tracks/161184744/processed_ATL10-01_20181104143933_05650101_001_01.h5\n"
     ]
    }
   ],
   "source": [
    "directory = '/home/jovyan/segtrax/data/ATL10_tracks/*/*'\n",
    "files = glob.glob(directory)\n",
    "\n",
    "traj_list = []\n",
    "\n",
    "for f in files[0:10]:\n",
    "    \n",
    "    segment_id, segment_length, date, lons, lats, freeboard = rd.getATL10(f, beam='gt1l')\n",
    "    \n",
    "    for sid, slen, d, la, lo, fb in zip(segment_id, segment_length, date, lats, lons, freeboard):\n",
    "        traj_list.append(Trajectory(sid, slen, d, la, lo, fb))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Trajectory for segment 1 with length 8259610.951683317"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "traj_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3340717"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(traj_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
